package com.yanqu.road.entity.activity.wanyao.config;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.wanyao.entity.WanYaoBlockData;
import com.yanqu.road.entity.enums.eActivityConfigType;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WanYaoConfig {
    //五帝钱--积分兑换道具
    private int scoreItemId;
    //惊魂花--激活妖王天赋
    private int talentItemId;
    //妖行丹--体力包道具
    private int powerItemId;
    //体力cd时间
    private int powerCdTime;
    //体力恢复时间
    private int powerRecoverTime;
    //体力上限
    private int powerMax;
    //体力初始值
    private int powerInit;   //天赋配置



    private Map<Integer,Map<Integer,WanYaoTalentConfig>>  wanYaoTalentConfigMap;
    //关卡配置
    private Map<Integer,WanYaoMissionConfig> wanYaoMissionConfigMap;
    //妖王配置
    private Map<Integer,WanYaoMonsterKingConfig> wanYaoMonsterKingConfigMap;
    //npc配置
    private Map<Integer,WanYaoNpcConfig> getWanYaoNpcConfigMap;

    //每次体力妖王获得的积分
    private int scorePerEnergy;

    //----------------下面是引导用的-----------------

    private List<WanYaoBlockData> initGuideList;

    private List<WanYaoBlockData> firstGuideList;

    private List<WanYaoBlockData> secondGuideList;

    private List<WanYaoBlockData> thirdGuideList;

    private List<WanYaoBlockData> fourthGuideList;

    private List<WanYaoBlockData> fifthGuideList;


    private List<Integer> guideClick1;

    private List<Integer> guideClick2;

    //一点体力妖王获得的经验
    private int expPerEnergy;

    public WanYaoConfig(Map<Integer, Map<Integer, WanYaoTalentConfig>> wanYaoTalentConfigMap,
                        Map<Integer, WanYaoMissionConfig> wanYaoMissionConfigMap,
                        Map<Integer, WanYaoMonsterKingConfig> wanYaoMonsterKingConfigMap,
                        Map<Integer, WanYaoNpcConfig> getWanYaoNpcConfigList,
                        Map<String, ActivityConfig> activityConfigMap
                        ) {
        this.wanYaoTalentConfigMap = wanYaoTalentConfigMap;
        this.wanYaoMissionConfigMap = wanYaoMissionConfigMap;
        this.wanYaoMonsterKingConfigMap = wanYaoMonsterKingConfigMap;
        this.getWanYaoNpcConfigMap = getWanYaoNpcConfigList;
        if(activityConfigMap.containsKey("WANYAO_SCORE_ITEM_ID")){
            this.scoreItemId = activityConfigMap.get("WANYAO_SCORE_ITEM_ID").getIntValue();
        }
        if(activityConfigMap.containsKey(eActivityConfigType.EXCHANGE_SCORE_ITEM_ID.getName())){
            this.scoreItemId = activityConfigMap.get(eActivityConfigType.EXCHANGE_SCORE_ITEM_ID.getName()).getIntValue();
        }
        this.talentItemId = activityConfigMap.get("WANYAO_BEAN_ITEM_ID").getIntValue();
        this.powerItemId = activityConfigMap.get("WANYAO_ENERGY_ITEM_ID").getIntValue();
        this.powerCdTime = activityConfigMap.get("WANYAO_ENERGY_CD").getIntValue();
        this.powerRecoverTime = activityConfigMap.get("WANYAO_ENERGY_CD_NUM").getIntValue();
        this.powerMax = activityConfigMap.get("WANYAO_ENERGY_LIMIT").getIntValue();
        this.powerInit = activityConfigMap.get("WANYAO_ENERGY_INIT").getIntValue();
        this.expPerEnergy = activityConfigMap.get("WANYAO_ACHIEVE_EXPERIENCE").getIntValue();
        this.scorePerEnergy = activityConfigMap.get("WANYAO_ENERGY_GET_SCORE").getIntValue();

        //level
        this.initGuideList = initGuideList(activityConfigMap.get("WANYAO_CHESSBOARD").getValue());
        this.firstGuideList = initGuideList(activityConfigMap.get("WANYAO_GUIDE_DROP_1").getValue());
        this.secondGuideList = initGuideList(activityConfigMap.get("WANYAO_GUIDE_DROP_2").getValue());
        this.thirdGuideList = initGuideList(activityConfigMap.get("WANYAO_GUIDE_DROP_3").getValue());
        this.fourthGuideList = initGuideList(activityConfigMap.get("WANYAO_GUIDE_DROP_4").getValue());
        this.fifthGuideList = initGuideList(activityConfigMap.get("WANYAO_GUIDE_DROP_5").getValue());


        //x,y
        this.guideClick1 = activityConfigMap.get("WANYAO_GUIDE_CLICK_1").getIntListValue(",");
        this.guideClick2 = activityConfigMap.get("WANYAO_GUIDE_CLICK_2").getIntListValue(",");





    }

    public Map<Integer,WanYaoBlockData> getInitGuideBoard(int step){
        Map<Integer,WanYaoBlockData> map = new ConcurrentHashMap<>();
        List<WanYaoBlockData> tmpData = null;
        if (step == 0){
            tmpData = initGuideList;
        }else if (step == 1){
            tmpData = firstGuideList;
        }else if (step == 2){
            tmpData = secondGuideList;
        }else if (step == 3){
            tmpData = thirdGuideList;
        }else if (step == 4) {
            tmpData = fourthGuideList;
        }else if (step == 5){
            tmpData = fifthGuideList;
        }
        if (tmpData == null){
            return null;
        }else {
            for (WanYaoBlockData blockData : tmpData) {
                WanYaoBlockData copy = blockData.copy();
                map.put(copy.getBlockId(), copy);
            }
        }
        return map;

    }

    public List<WanYaoBlockData> initGuideList(String guideListStr){
        List<WanYaoBlockData> guideList = new ArrayList<>();

        List<String> strings = StringUtils.stringToStringList(guideListStr, "\\|");

        int index = 0;
        for (int y = 0; y < 5; y++) {
            for (int x = 0; x < 5; x++) {
                String s = strings.get(index);
                index++;
                List<Integer> integerList = StringUtils.stringToIntegerList(s, "=");
                WanYaoBlockData blockData = new WanYaoBlockData();
                blockData.setBlockId(integerList.get(0));
                blockData.setX(x);
                blockData.setY(y);
                blockData.setBlockLevel(integerList.get(1));
                guideList.add(blockData);
            }
        }

        return guideList;
    }



    public int getScoreItemId() {
        return scoreItemId;
    }

    public int getTalentItemId() {
        return talentItemId;
    }

    public int getPowerItemId() {
        return powerItemId;
    }

    public int getPowerCdTime() {
        return powerCdTime;
    }

    public int getPowerRecoverTime() {
        return powerRecoverTime;
    }

    public int getPowerMax() {
        return powerMax;
    }

    public int getPowerInit() {
        return powerInit;
    }

    public Map<Integer, Map<Integer, WanYaoTalentConfig>> getWanYaoTalentConfigMap() {
        return wanYaoTalentConfigMap;
    }

    public Map<Integer, WanYaoMissionConfig> getWanYaoMissionConfigMap() {
        return wanYaoMissionConfigMap;
    }

    public Map<Integer, WanYaoMonsterKingConfig> getWanYaoMonsterKingConfigMap() {
        return wanYaoMonsterKingConfigMap;
    }

    public Map<Integer, WanYaoNpcConfig> getGetWanYaoNpcConfigMap() {
        return getWanYaoNpcConfigMap;
    }

    public int getExpPerEnergy() {
        return expPerEnergy;
    }


    public List<Integer> getGuideClick1() {
        return guideClick1;
    }

    public List<Integer> getGuideClick2() {
        return guideClick2;
    }

    public int getScorePerEnergy() {
        return scorePerEnergy;
    }

    public List<WanYaoBlockData> getInitGuideList() {
        return initGuideList;
    }

    public List<WanYaoBlockData> getFirstGuideList() {
        return firstGuideList;
    }

    public List<WanYaoBlockData> getSecondGuideList() {
        return secondGuideList;
    }

    public List<WanYaoBlockData> getThirdGuideList() {
        return thirdGuideList;
    }

    public List<WanYaoBlockData> getFourthGuideList() {
        return fourthGuideList;
    }

    public List<WanYaoBlockData> getFifthGuideList() {
        return fifthGuideList;
    }
}
